//
//  FSSpecialTopicCellTableViewCell.m
//  fanshu
//
//  Created by mh on 16/3/28.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSDiscoverSpecialCell.h"
#import "FSDiscoverSpecialModel.h"
#import "FSButton.h"
@interface FSDiscoverSpecialCell ()
@property(nonatomic,weak)FSButton *attentBtn;
@property(nonatomic,weak)UIView *pointView;
@end
@implementation FSDiscoverSpecialCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initWithSubViews];
    }
    return self;
}

- (void)initWithSubViews{
    //专题图标
    UIImageView *iconView = [[UIImageView alloc] init];
    [self.contentView addSubview:iconView];
    self.iconView = iconView;
    //专题名称
    UILabel *special = [[UILabel alloc] init];
    special.font = specialFont;
    [self.contentView addSubview:special];
    self.special = special;
    //发布文章总数
    UILabel *countOfArticle = [[UILabel alloc] init];
    countOfArticle.textColor = colorOfText(183, 183, 183);
    countOfArticle.font = countOfArticleFont;
    [self.contentView addSubview:countOfArticle];
    self.countOfArticle = countOfArticle;
    //关注人数
    UILabel *countOfAttented = [[UILabel alloc] init];
    countOfAttented.textColor = colorOfText(183, 183, 183);
    countOfAttented.font = countOfAttentedFont;
    [self.contentView addSubview:countOfAttented];
    self.countOfAttented = countOfAttented;
    //关注按钮
    FSButton *attentBtn = [[FSButton alloc] init];
    attentBtn.titleLabel.font = attentBtnFont;
    [attentBtn setBackgroundImage:[UIImage resizableImageWithImageName:@"button_orange_base"] forState:UIControlStateNormal];
    [attentBtn setTitle:@"关注" forState:UIControlStateNormal];
    [attentBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.contentView addSubview:attentBtn];
    self.attentBtn = attentBtn;
    //专题介绍
    UILabel *introduction = [[UILabel alloc] init];
    introduction.textColor = colorOfText(138, 138, 138);
    introduction.font = introductionFont;
    introduction.numberOfLines = 0;
    [self.contentView addSubview:introduction];
    self.introduction = introduction;
    
    //分割点
    UIView *pointView = [[UIView alloc] init];
    pointView.backgroundColor = colorOfText(222, 222, 222);
    pointView.layer.cornerRadius = 1;
    pointView.layer.masksToBounds = YES;
    [self.contentView addSubview:pointView];
    self.pointView = pointView;
}

- (void)setModel:(FSDiscoverSpecialModel *)model{
    _model = model;
    //专题图标
    self.iconView.image = [UIImage imageNamed:model.icon];
    //专题名称
    self.special.text = model.special;
    //发布文章总数
    self.countOfArticle.text = [NSString stringWithFormat:@"%@篇文章",model.countOfArticle];
    //关注人数
    self.countOfAttented.text = [NSString stringWithFormat:@"%@人关注",model.countOfAttented];
    //关注按钮 状态
    if(model.attented){//已关注
        self.attentBtn.enabled = NO;
    }else{//未关注
        self.attentBtn.enabled = YES;
    }
    //专题介绍
    self.introduction.text = model.introduction;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    //专题图标
    self.iconView.frame = self.model.iconViewF;
    //专题名称
    self.special.frame = self.model.specialF;
    //发布文章总数
    self.countOfArticle.frame = self.model.countOfArticleF;
    //分割点
    self.pointView.frame = CGRectMake(CGRectGetMaxX(self.countOfArticle.frame) + 2, CGRectGetMaxY(self.countOfArticle.frame) - self.countOfArticle.height * 0.5, 2, 2);
    //关注人数
    self.countOfAttented.frame = self.model.countOfAttentedF;
    //关注按钮
    self.attentBtn.frame = self.model.attentedBtnF;
    //专题介绍
    self.introduction.frame = self.model.introductionF;
}

@end
